<?php defined('SYSPATH') OR die('No direct access allowed.');

class FormTemplate_Plugin extends WB_FormItem {
	
	protected $template, $func, $func_params, $necessary_fields, $join_exp;
	
	public function __construct($name='', $params=array())
	{
		parent::__construct($name, $params);
		
		$this->db_tablename = null;
		
		$this->table_columns = null;
		$this->form_columns = null;
		$this->db_columns = null;
		
		$this->template = isset($this->params['template']) ? $this->params['template'] : '';
		$this->func = isset($this->params['func']) ? $this->params['func'] : '';
		$this->func_params = ! empty($this->params['func_params']) ? $this->params['func_params'] : array();
	}
	
	public function render_cell() {return null;}
	public function prep_db() {return null;}
	
	public function render_item()
	{
		if ($this->func)
		{
			$func = $this->func;
			$template = Kohana::instance()->$func($this->value);
		}
		else
		{
			$template = $this->template;
			
			$search = array();
			if (is_array($this->value))	foreach ($this->value as $k=>$v) $search['{'.$k.'}'] = $v;
			$search['{base_url}'] = url::base();
			$search['{site_url}'] = url::site();
			$template = str_replace(array_keys($search), $search, $template);
		}
		return $template;
	}
}

//End of FormTemplate_Plugin Library